package uk.org.landeg.euler.problems.unported;

import java.util.HashMap;

/** hashmap with a modified put : will only put if the new value exceeds the existing one **/ 

public class MaxHashMap<K, V extends Comparable<V>> extends HashMap<K, V>{
	private static final long serialVersionUID = -7222732672660713137L;

	@Override @SuppressWarnings("unchecked")
	public V put(K key, V value) {
		if (value instanceof Comparable<?> && containsKey(key)) {
			if (value.compareTo(get((Comparable<V>)key)) > 0) {
				return super.put(key, value);
			} else {
				return null;
			}
		}
		else return super.put(key, value);
	}
}
